package com.broada.apm.indicator.api;

import java.util.List;
import java.util.Map;

import com.broada.apm.indicator.api.common.ApmDataIndicatorException;
import com.broada.apm.indicator.api.model.SearchCondition;
import com.broada.apm.model.BaseResource.RESOURCE_TYPE;
import com.broada.apm.model.PagingList;
import com.broada.apm.model.PerformanceView;

public interface PerformanceQueryService {
	/**
	 * 根据资源类型 查询资源性能
	 * 
	 * @param applicationId
	 * @param type
	 * @param searchCondition
	 * @return
	 */
	public PagingList<PerformanceView> queryPerf(SearchCondition searchCondition) throws ApmDataIndicatorException;

	/**
	 * 统计查询应用系统、服务、资源等性能数据 必须指定使用Aggregations.TermsBuilder
	 * 
	 * @param applicationId
	 * @param type
	 * @param clz
	 * @param searchCondition
	 * @return
	 * @throws ApmDataIndicatorException
	 */
	public List<PerformanceView> queryAggregationTermsPerf(String applicationId, RESOURCE_TYPE type,
			SearchCondition searchCondition) throws ApmDataIndicatorException;
	
	/**
	 * 按时间颗粒度查询应用系统、服务、资源等性能数据 不支持查询维度 必须指定使用Aggregations.DateHistogram
	 * 
	 * @param applicationId
	 * @param type
	 * @param clz
	 * @param searchCondition
	 * @return
	 * @throws ApmDataIndicatorException
	 */
	public List<PerformanceView> queryAggregationDateHistogramPerf(String applicationId,
			SearchCondition searchCondition) throws ApmDataIndicatorException;

	public PerformanceView queryAggregationSingelePerfByDimensionType(String applicationId,  SearchCondition searchCondition) throws ApmDataIndicatorException;
	
	public List<Map<String, Object>> queryErrorCodeCount(SearchCondition searchCondition) throws ApmDataIndicatorException;
	
	public Map<String, Object> queryAggregationPerfForThreshold(String applicationId, RESOURCE_TYPE type,
			SearchCondition searchCondition) throws ApmDataIndicatorException;

	public List<PerformanceView> queryAggregationTermsPerf(String appId, String[] indices, String indextype, SearchCondition usersCondition)  throws ApmDataIndicatorException;
	
	/**
	 * 获取交易明细
	 * @param resource
	 * @param con
	 * @return
	 * @throws ApmDataIndicatorException
	 */
	public PagingList<PerformanceView> queryTransactions(SearchCondition con) throws ApmDataIndicatorException;
	
	public List<PerformanceView> queryServiceAggregationTermsPerf(RESOURCE_TYPE service, SearchCondition add) throws ApmDataIndicatorException;
	
	public PagingList<PerformanceView> queryTermsCount(SearchCondition add) throws ApmDataIndicatorException;

	
	/**
	 * terms嵌套查询
	 * @param applicationId
	 * @param type
	 * @param searchCondition
	 * @return
	 * @throws ApmDataIndicatorException
	 */
	public List<PerformanceView> queryErrorTermsPerf(String applicationId, RESOURCE_TYPE type,
			SearchCondition searchCondition) throws ApmDataIndicatorException;


	public PagingList<PerformanceView> querySubAggregationData(SearchCondition add) throws ApmDataIndicatorException;

	public List<PerformanceView> queryAggregationTermsPerfForApps(RESOURCE_TYPE application, SearchCondition add) throws ApmDataIndicatorException;

	
	// 新方法从这里开始
	/**
	 * 聚合查询
	 * @param con
	 * @return
	 * @throws ApmDataIndicatorException
	 */
	public List<PerformanceView> queryAggregationTermsPerf(SearchCondition con) throws ApmDataIndicatorException;

	/**
	 * 查询原始记录
	 * @param con
	 * @return
	 * @throws ApmDataIndicatorException
	 */
	public List<PerformanceView> queryPerformanceDetail(SearchCondition con) throws ApmDataIndicatorException;

}
